package org.csu.mypetstore.controller;

import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/account")
public class AccountController {
    @Autowired
    AccountService accountService;

    @GetMapping("/editAccount")
    public String editAccount(String username, Model model){
        Account account = accountService.getAccountByUserId(username);
        model.addAttribute("account",account);
        return "account/account";
    }

    @GetMapping("/viewAccount")
    public String viewAccount(Model model){
        List<Account> accountList= accountService.getAllAccount();
        model.addAttribute("accountList",accountList);
        return "account/managementAccount";
    }

<<<<<<< HEAD
    @GetMapping("/viewAccountChange")
    public String accountChange(String userId,Model model){
        Account account = accountService.getAccountByUserId(userId);
        model.addAttribute("account",account);
        return "account/accountChange";
=======
    @GetMapping("/change")
    public  String viewchange(String username,Model model){
        Account account=accountService.getAccountByUserId(username);
        model.addAttribute("account",account);
        return "account/accountchange";
    }

    @GetMapping("/delete")
    public String viewdelete(String username,Model model){
        accountService.deleteAccount(username);
        System.out.println(username);
        System.out.print(16);
        List<Account> accountList= accountService.getAllAccount();
        model.addAttribute("accountList",accountList);
        return "account/managementAccount";
>>>>>>> f7eee4e2fb18f22b63320e819889ecc96c4f0263
    }
}
